<?php 
	namespace Admin\Controller;
	
	class LinksController extends AdminController
	{
		// 显示友情链接
		public function index()
		{	
			$links = M('links');
			$show = $links->select();

			// var_dump($show);
			$this->assign('link',$show);
			$this->display();
		}


		// 添加
		public function doadd()
		{
			

			$link = M('links');

			if(empty(I()['name'])){
				$this->error('链接名称不能为空!!');
				exit;
			}
			
			if($link->add(I())>0){
				$this->success("添加链接成功！",U('Links/index'));
			}else{
				$this->error("添加链接失败");
			}
		}

		// 删除
		public function del()
		{
			
			$link = M('links');
			
			if($link->where(I())->delete()>0){
				$this->success("删除链接成功！",U('Links/index'));
			}else{
				$this->error("删除链接失败");
			}

		}

		// edit查询
		public function edit()
		{
			$link = M('links');

			$array = $link->where(I())->find();

			// var_dump($array);
			
			$this->assign('vo',$array);
			$this->display();
		} 

		// 执行edit修改
		public function doedit()
		{
			$link = M('links');

			if($link->save(I())>0){
				$this->success("修改链接成功！",U('Links/index'));
			}else{
				$this->error("修改链接失败");
			}
		}

	}
